<?php
/**
 * @purpose: 对“通知”类型中子类型为1(新增评论)的编码与解码文件
 * @author: Mandel Woo <wuzhijian@snda.com>

 * @memo: 参阅母板文件
 */
require_once(dirname(__FILE__)."/../../../models/user/UCModUserInfo.php");


function msg_notice_type1_encoder() {
	$fields = array("usr_id","atl","url");

	foreach($fields as $k => $v) {
		eval("\${$v}=func_get_arg($k);");
	}

	$atl = utf_substr($atl, 200);

	#用户A  评论了你的 ***，赶快看看去吧！
	return serialize(array(
			"usr_id" => $usr_id,
			"atl"    => $atl,
			"url"    => $url,
			));
}

function msg_notice_type1_decoder() {
	$fields = array("id","receiverid","content","createTime","changeFlag","fmt");

	foreach($fields as $k => $v) {
		eval("\${$v}=func_get_arg($k);");
	}

	$data = unserialize($content);
	$o_usr    = UCModUserInfo::getUser($data['usr_id']);
	$nickname = $o_usr->getName();
	$nickname == '' && $nickname = $data['usr_id']; #取不到昵称

	$usr = "<a href=\"".get_user_home_url($data['usr_id'])."\" target='_blank'>{$nickname}</a>";

	#!!!输出处将不做html转义，须保证用户输入数据的安全
	if ($fmt == 'line') {
		return sprintf("用户%s评论了你的“%s”，赶快看看去吧！", $usr, $data['atl']);

	} else if ($fmt == 'box') {
		$html = sprintf("用户%s评论了你的“%s”，赶快看看去吧！", $usr, "<a href=\"".$data['url']."\" target=\"_blank\">".$data['atl']."</a>");
		return '<div class="font14">' . $html . '</div>';

	} else {
		return '';
	}
}



